<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <script>

    // function Person(name, age, gender) {
    //   this.name = name
    //   this.age = age
    //   this.gender = gender
    //   this.sayName = function () {
    //     alert(this.name);
    //   }
    // }
    // var per = new Person("孙悟空", 18, "男");
    // var per2 = new Person("猪八戒", 20, "男")
    // function Dog(name, age, gender) {
    //   this.name = name
    //   this.age = age
    //   this.gender = gender
    // }
    // var dog = new Dog("旺财", 4, "雄")
    // console.log(per);
    // //当我们直接在页面中打印一个对象时，事件上是输出的对象的toString()方法的返回值
    // console.log(per2);
    // console.log(dog);


    class Parent {
      constructor(name) {
        this.name = name;
      }
    }
    class Child extends Parent {
      constructor(name, age) {
        super(name);
        this.age = age;
      }
    }
    const child = new Child("xiaohua", 18)

    // console.log(Child);
    // console.log(child.__proto__);
    // console.log(child.__proto__.__proto__);
    // console.log(Parent.prototype);
    // console.log(Parent.prototype.prototype);


    // function Animal(name, age) {
    //   this.name = name;
    //   this.age = age;
    // }
    // Animal.prototype.eat = function () {
    //   console.log('吃吃吃')
    // }
    // var dog = new Animal('狗狗', 12)

    // console.log('-----dog-----');
    // console.log(dog);
    // console.log('constructor', dog.constructor);
    // console.log('pro', dog.__proto__);
    // console.log('pro.pro', dog.__proto__.__proto__);
    // console.log('pro.pro.pro', dog.__proto__.__proto__.__proto__);
    // console.log('--------------');
    // console.log('--------------');
    // console.log('-----Animal-----');
    // console.log(Animal);
    // console.log('constructor', Animal.constructor);
    // console.log('prot', Animal.prototype);
    // console.log('prot.pro', Animal.prototype.__proto__);
    // console.log('prot.pro.pro', Animal.prototype.__proto__.__proto__);


    // 原型链的使用
    function People (name, age) {
      this.name = name;
      this.age = age;
    }
    function Student(name ,age) {
      this.name = name;
      this.age = age;
      console.log(this);
      this.sayHi = function () {
        console.log('内部 Hello, I am ' + this.name + " , nice to meet you!");
      }
    }

    Student.prototype.sayHi = function() {
      console.log('Hello, I am ' + this.name + " , nice to meet you!");
    }

    Student.prototype.read = function(bookName) {
      console.log('I am reading 《' + bookName + "》.");
    }

    let nick = new Student('Nick', 15);
    console.log(nick);
    nick.sayHi()
    nick.read('西游记');
  </script>
</body>

</html>